/**
 * 项目名称：MCOMMON
 * 包名称：com.mt.common.log
 * 文件名称：OptLog.java
 */
package com.mt.system.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.mt.component.domain.Common;
import com.mt.utils.StringUtils;



/**
 * 类名称：OptLog <br>
 * 类描述：用户操作日志 <br>
 * 创建人： 马腾 <br>
 * 创建时间：2012-10-18 下午11:37:13 <br>
 */
@Entity
@Table(name="CFG_LOG_OPT")
public class OptLog extends Common implements Serializable {
	
	private static final long serialVersionUID = 4987918708916802677L;
	
	private User user;//操作的用户
	private Permission permission;//操作权限
	private String optIp;//操作发生的IP地址
	private Date optTime;//操作日志时间
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="USER_ID")
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="PMS_ID")
	public Permission getPermission() {
		return permission;
	}
	public void setPermission(Permission permission) {
		this.permission = permission;
	}
	
	@Column(name = "OPT_IP" , length=32)
	public String getOptIp() {
		return optIp;
	}
	public void setOptIp(String optIp) {
		this.optIp = optIp;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "OPT_TIME")
	public Date getOptTime() {
		return optTime;
	}
	public void setOptTime(Date optTime) {
		this.optTime = optTime;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof OptLog){
			OptLog optLog = (OptLog)obj;
			if(StringUtils.isEmpty(optLog.getId())) return false;
			return optLog.getId().equals(getId());
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return getId()==null ? 0 : getId().hashCode();
	}
	
	@Override
	public String toString() {
		return OptLog.class.getName() + "[" + id + "]";
	}
}
